//
//  ColorViewController.m
//  便签
//
//  Created by  on 2022/9/29.
//

#import "ColorViewController.h"
#import "ColorCell.h"

@interface ColorViewController ()
@property (strong, nonatomic) IBOutlet UICollectionView *colllectionView;
@end

@implementation ColorViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}
- (void)initUI{
    [self.colllectionView registerNib:[ColorCell nib] forCellWithReuseIdentifier:[ColorCell ID]];
}
+ (void)pop:(void (^)(NSString * _Nonnull))block{
    ColorViewController * vc = [ColorViewController new];
     vc.block = block;
    [[self currentVC] presentViewController:vc animated:NO completion:nil];
}
- (NSMutableArray *)titles{
    if (!_titles) {
        _titles = [NSMutableArray arrayWithArray:@[@"Blue",@"Purple",@"Yellow",@"Green",@"Orange",@"Black"]];
    }
    return _titles;
}
- (NSMutableArray *)colors{
    if (!_colors) {
        _colors = [NSMutableArray arrayWithArray:@[@"#0B24FB",@"#7356BF",@"#FD9C14",@"#05944F",@"#FF6937",@"#09101D"]];
    }
    return _colors;
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return  self.colors.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ColorCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:[ColorCell ID] forIndexPath:indexPath];
    cell.coloView.bgHexColor = self.colors[indexPath.row];
    cell.colorName.text = self.titles[indexPath.row];
    return  cell;
}

#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.block) {
        self.block(self.colors[indexPath.row]);
    }
}

#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return  CGSizeMake(60,80);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return  UIEdgeInsetsMake(12, 16, 16, 12);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 6;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 6;
}

@end
